package yawning.mew.equipment;

import java.lang.ref.WeakReference;
import java.util.WeakHashMap;

public class MemoryCacheItemSource extends ItemSource {
	private WeakHashMap<RawItem,WeakReference<RawItem>> mCache = new WeakHashMap<RawItem,WeakReference<RawItem>>(); 
	
	@Override
	public RawItem getById(int id) {
		RawItem item = new RawItem();
		item.id = id;
		if (mCache.containsKey(item)) {
			item = mCache.get(item).get();
			if (item != null) return item;
		}
		item = mNext.getById(id);
		if (item != null) mCache.put(item, new WeakReference<RawItem>(item));
		return item;
	}
}
